package com.hq.ims.data.utils;

import com.hq.ims.data.entityenum.EnumCompanyLevel;
import com.hq.ims.data.interiorenum.EnumInsideFindDataScore;
import com.hq.utils.util.StringUtils;
import lombok.Data;

import java.io.Serializable;

/**
 * 当前线程存储类
 * <p>
 * jbp
 */
public class CurThreadLocalUtil {

    private static final CurThreadLocalUtil INSTANCE = new CurThreadLocalUtil();
    private ThreadLocal<ThreadStore> threadLocal = new ThreadLocal();

    private CurThreadLocalUtil() {
    }

    public static CurThreadLocalUtil getInstance() {
        return INSTANCE;
    }

    public void bind(ThreadStore user) {
        this.threadLocal.set(user);
    }

    public ThreadStore get() {
        return this.threadLocal.get();
    }

    public void remove() {
        this.threadLocal.remove();
    }

    @Data
    public static class ThreadStore implements Serializable {

        /**
         * 启动流程后返回的流程实例ID
         */
        private String runProcessAfterId;

        /**
         * 从当前公司需要查找所有子公司及当前的数据的公司Id
         */
        private String orgId;
        private EnumCompanyLevel orgLv;
        private EnumInsideFindDataScore findDataScore;
        private String dataLibCompanyFieldName;
        private String dataLibProjectFieldName;
        private Boolean ignoreSqlSelect = false;


        public void clear() {
            runProcessAfterId = StringUtils.EMPTY;
            orgId = StringUtils.EMPTY;
            orgLv = null;
            findDataScore = null;
            ignoreSqlSelect = false;
        }
    }
}
